<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head> 
	<title>Videshop POS</title> 
	<link href="../css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<f:view>
		<table border="0" cellpadding="0" cellspacing="10">
			<tr>
				<td colspan="2"><h1>Videoshop POS</h1></td>
			</tr>
			<tr>
				<td valign="top">
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td>
								<!-- User section -->
								<f:subview id="userSection">
									<jsp:include page="user.jsp"/>
								</f:subview>
							</td>
						</tr>
						<tr>
							<td>
								<!-- Menu section -->
								<f:subview id="menuSection">
									<jsp:include page="menu.jsp"/>
								</f:subview>
							</td>
						</tr>
					</table>
				</td>
				<td valign="top" class="mainSection">
					<c:choose>
						<c:when test="${!empty userSection.staff && userSection.staff.manager}">
							<h2>Stock report</h2>

							<h:form>
								<h:panelGrid columns="2">
									<h:outputText styleClass="label" value="Store"/>
									<h:selectOneListbox	styleClass="select200" size="1" value="#{reportSection.selectedStoreId}">
										<f:selectItems value="#{reportSection.availableStores}"/>
									</h:selectOneListbox>
									<h:commandLink styleClass="button" action="#{reportSection.generateStockReport}">
										<f:verbatim escape="true">Report</f:verbatim>
									</h:commandLink>
								</h:panelGrid>
							</h:form>
							
							<c:if test="${!empty reportSection.stockReportStores}">
								<table class="dataTable" border="0" cellpadding="0" cellspacing="0">
									<tr>
										<th width="200">Store</th>
										<th width="250">Title</th>
										<th width="60">Total</th>
										<th width="60">Rented</th>
										<th width="60">Available</th>
									</tr>
								<c:forEach items="${reportSection.stockReportStores}" var="store">
									<tr>
										<td colspan="5">${store.store.storeName}</td>
									</tr>
									<c:forEach items="${store.titles}" var="titleEntry">
										<tr>
											<td>&nbsp;</td>
											<td>${titleEntry.value.title.titleName}</td>
											<td>${titleEntry.value.totalCopies}</td>
											<td>${titleEntry.value.unAvailableCopies}</td>
											<td>${titleEntry.value.availableCopies}</td>
										</tr>
									</c:forEach>
									<tr class="subSummary">
										<td colspan="2">Total</td>
										<td>${store.totalCopies}</td>
										<td>${store.unAvailableCopies}</td>
										<td>${store.availableCopies}</td>
									</tr>
								</c:forEach>
								</table>
							</c:if>
							
						</c:when>
						<c:otherwise>
							Please login
						</c:otherwise>
					</c:choose>
					
				</td>
			</tr>
		</table>
	</f:view>
</html>